package com.cxz.study.infra.messaging.eventPublisher;

import com.cxz.study.domain.order.OrderEventPublisher;
import com.cxz.study.domain.order.event.OrderCancelledEvent;
import com.cxz.study.domain.order.event.OrderCreatedEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * @className: OrderEventPublisherImpl
 * @author: ocxz1
 * @date: 2025/6/15 上午11:27
 * @Version: 1.0
 * @description: ddd-struct3
 */
@RequiredArgsConstructor
@Service
public class OrderEventPublisherImpl implements OrderEventPublisher {

    private final KafkaTemplate<String, String> kafkaTemplate;

    public void publish(OrderCreatedEvent orderCreatedEvent) {
        kafkaTemplate.send("order-created-topic", orderCreatedEvent.getOrderId().toString());
    }

    @Override
    public void publish(OrderCancelledEvent orderCancelledEvent) {
        kafkaTemplate.send("order-cancelled-topic", orderCancelledEvent.getOrderId().toString());
    }
}
